package com.extsci.webmail.web.controller;

import cc.ccoke.validate.annotation.ParamVerify;
import com.extsci.webmail.common.entity.http.ObjectRestResponse;
import com.extsci.webmail.common.entity.http.ResponseStatus;
import com.extsci.webmail.web.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.Set;

/**
 * 邮件
 * @author ccoke
 */
@RestController
@RequestMapping("/user")
public class UserController {
    private final MailService mailService;

    @Autowired
    public UserController(MailService mailService) {
        this.mailService = mailService;
    }

    /**
     * 获取最近联系人列表
     */
    @GetMapping("/sender/recent")
    @ParamVerify
    public ObjectRestResponse<Set<String>> getRecentSenders(@RequestParam("count") Integer count) {
        if (count < 1) {
            return new ObjectRestResponse<>(ResponseStatus.SUCCESS, new HashSet<>());
        }
        return mailService.getRecentSenders(count);
    }

}
